package com.ars.listStatistics;

import com.ars.db.DBTools;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Order {

    // 座位类型
    private static final int FIRST_SEATS = 1;
    private static final int BUSINESS_SEATS = 2;
    private static final int ECONOMY_SEATS = 3;
    // 票种类型
    private static final int NORMAL_TICKET = 1;
    private static final int SPECIAL_TICKET = 2;

    // 票种类型
    private int ticketType;
    // 舱位级别
    private int seatsType;
    // 全票价格
    private double fullFare;
    // 折扣
    private double discount;
    // 最终售价
    private double price;

    private String Oid;
    private String Passenger_name;
    private String Passenger_id;
    private java.sql.Date Date;
    private String Fid;

    public Order() {
    }

    ;

    public Order(int oid) {
        String sql = "SELECT price,discount,seats_type,ticket_type FROM schedule,flight,orders WHERE flight.sid = schedule.sid and flight.fid = orders.fid AND oid = "
                + oid;
        ResultSet rs = new DBTools().query(sql);
        try {
            if (rs.next()) {
                this.fullFare = rs.getDouble("price");
                this.discount = rs.getDouble("discount");
                this.seatsType = rs.getInt("seats_type");
                this.ticketType = rs.getInt("ticket_type");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // 获得最终价格
    public double getPrice() {
        // 计算价格
        price = fullFare;
        // 打航班折
        price = price * discount;
        // 打舱位折
        if (seatsType == BUSINESS_SEATS) {
            price = price * 0.7;
        } else if (seatsType == ECONOMY_SEATS) {
            price = price * 0.5;
        }
        // 打票种折
        if (ticketType == SPECIAL_TICKET) {
            price = price * 0.5;
        }

        return price;
    }

    public String getOid() {
        return Oid;
    }

    public void setOid(String oid) {
        Oid = oid;
    }

    public String getPassenger_name() {
        return Passenger_name;
    }

    public void setPassenger_name(String passenger_name) {
        Passenger_name = passenger_name;
    }

    public String getPassenger_id() {
        return Passenger_id;
    }

    public void setPassenger_id(String passenger_id) {
        Passenger_id = passenger_id;
    }

    public int getSeats_type() {
        return seatsType;
    }

    public void setSeats_type(int seats_type) {
        seatsType = seats_type;
    }

    public int getTicket_type() {
        return ticketType;
    }

    public void setTicket_type(int ticket_type) {
        ticketType = ticket_type;
    }

    public java.sql.Date getDate() {
        return Date;
    }

    public void setDate(java.sql.Date date2) {
        Date = date2;
    }

    public String getFid() {
        return Fid;
    }

    public void setFid(String fid) {
        Fid = fid;
    }
}
